#ifndef INC_SSC_BSP_H_
#define INC_SSC_BSP_H_

#include <stdint.h>
#include "stm32f4xx.h"
#include "tim.h"

#define ENABLE_GLOBAL_INT __enable_irq()
#define DISABLE_GLOBAL_INT __disable_irq()

#define ENABLE_AL_EVENT_INT ENABLE_GLOBAL_INT
#define DISABLE_AL_EVENT_INT DISABLE_GLOBAL_INT

// void spi_Select(void);
// void spi_Deselect(void);
// #define SELECT_SPI spi_Select();
// #define DESELECT_SPI spi_Deselect();

#define DESELECT_SPI HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
#define SELECT_SPI HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

void timer_Esc_IT_Start(void);
void timer_Esc_IT_Stop(void);

#define INIT_ESC_INT

#define INIT_SYNC0_INT
#define INIT_SYNC1_INT

#define ENABLE_SYNC0_INT HAL_NVIC_EnableIRQ(EXTI0_IRQn)
#define ENABLE_SYNC1_INT HAL_NVIC_EnableIRQ(EXTI1_IRQn)

#define INIT_ECAT_TIMER ;
#define START_ECAT_TIMER timer_Esc_IT_Start()

#ifndef HW_GetTimer
#define HW_GetTimer() TIM6->CNT  //(SysTick->LOAD - 	SysTick->VAL) //			// ((UINT16)(TMR7)) /**< \brief Access to the hardware timer*/
#endif

#define ENABLE_ESC_INT() HAL_NVIC_EnableIRQ(EXTI4_IRQn)
#define DISABLE_ESC_INT() HAL_NVIC_DisableIRQ(EXTI4_IRQn)

extern void Sync0Isr(void);
extern void Sync1Isr(void);
extern void TimerIsr(void);
extern void EcatIsr(void);

// #define DISABLE_SYNC0_INT HAL_NVIC_DisableIRQ(EXTI0_IRQn);
// #define ENABLE_SYNC0_INT HAL_NVIC_EnableIRQ(EXTI0_IRQn);

// #define DISABLE_SYNC1_INT HAL_NVIC_DisableIRQ(EXTI1_IRQn);
// #define ENABLE_SYNC1_INT HAL_NVIC_EnableIRQ(EXTI1_IRQn);

// #define ENABLE_ECAT_TIMER_INT __HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE | TIM_IT_BREAK);
// #define DISABLE_ECAT_TIMER_INT __HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE | TIM_IT_BREAK);

/**
 *	enable & disable PDI_IRQ, SYNC0, SYNC1 interrupt
 */

/**
 * Enable & Disable ESC INT, SYNC0, SYNC1, tim
 */
// void enable_Irq_Sync0_Sync1(void);
// void disable_Irq_Sync0_Sync1(void);

/**
 * Timer6 counter value get
 */
// uint32_t timer_Get_Value(void);
// #define HW_GetTimer() (timer_Get_Value())
// #define HW_ClearTimer()  (timer_Clear_Value())

#define ECAT_TIMER_INC_P_MS                1999

uint8_t WR_CMD(uint8_t cmd);

#endif /* INC_SSC_BSP_H_ */
